package com.guo.constellation.starfrag;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import java.util.List;

/**
 * @author glsite.com
 * @version $Rev$
 * @des ${TODO}
 * @updateAuthor $Author$
 * @updateDes ${TODO}
 */
public class StarPagerAdapter extends PagerAdapter {

    Context context;
    List<ImageView> imgList;

    public StarPagerAdapter(Context context, List<ImageView> imgList) {
        this.context = context;
        this.imgList = imgList;
    }

    @Override
    public int getCount() {
        return imgList.size();
    }

    //判断两次对象是否为同一个
    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == o;
    }

    //这两个方法是自己手动添加的


    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        //获取当前位置对象
        ImageView imageView = imgList.get(position);
        //进行加载对象
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        //获取当前位置对象
        ImageView imageView = imgList.get(position);
        //销毁对象
        container.removeView(imageView);
    }
}
